package com.example.lowbird.lowbird.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.FrameLayout;

import com.example.lowbird.lowbird.R;
import com.example.lowbird.lowbird.fragment.CategoryFragment;
import com.example.lowbird.lowbird.fragment.HostFragment;
import com.example.lowbird.lowbird.fragment.HotFragment;
import com.example.lowbird.lowbird.fragment.MyFragment;
import com.example.lowbird.lowbird.fragment.ShopingFragment;
import com.example.lowbird.lowbird.java.ECustomTabEntity;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private CommonTabLayout ct_main_bottom;
    private FrameLayout fl_main_center;
    private ArrayList<CustomTabEntity> tabEntitys = new ArrayList<CustomTabEntity>();
    private FragmentManager fm;

    private ArrayList<Fragment> fragments = new ArrayList<Fragment>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initview();
        Intent intent = getIntent();
        if (intent != null) {
            String intent1 = intent.getStringExtra("intent");
            if (intent1 != null) {
                if (intent1.equals("regist")) {
                    ct_main_bottom.setCurrentTab(4);

                }
            }

        }
    }

    /**
     * 加载控件
     */
    private void initview() {

        ct_main_bottom = ((CommonTabLayout) findViewById(R.id.ct_main_bottom));
        fl_main_center = ((FrameLayout) findViewById(R.id.fl_main_center));
        initfragments();
        inittabEntitys();
        ct_main_bottom.setTabData(tabEntitys, this, R.id.fl_main_center, fragments);

//
    }

    private void inittabEntitys() {
        ECustomTabEntity e1 = new ECustomTabEntity("主页", R.mipmap.icon_home_press, R.mipmap.icon_home);
        ECustomTabEntity e2 = new ECustomTabEntity("热卖", R.mipmap.icon_hot_press, R.mipmap.icon_hot);
        ECustomTabEntity e3 = new ECustomTabEntity("分类", R.mipmap.icon_discover_press, R.mipmap.icon_discover);
        ECustomTabEntity e4 = new ECustomTabEntity("购物车", R.mipmap.icon_cartfill_press, R.mipmap.icon_cart);
        ECustomTabEntity e5 = new ECustomTabEntity("我的", R.mipmap.icon_user_press, R.mipmap.icon_user);
        tabEntitys.add(e1);
        tabEntitys.add(e2);
        tabEntitys.add(e3);
        tabEntitys.add(e4);
        tabEntitys.add(e5);
    }

    /**
     * 初始化碎片
     */
    private void initfragments() {

        fragments.add(HostFragment.newInstance("1", "2"));
        fragments.add(HotFragment.newInstance("1", "2"));

        fragments.add(CategoryFragment.newInstance("1", "2"));
        fragments.add(ShopingFragment.newInstance("1", "2"));
        fragments.add(MyFragment.newInstance("1", "2"));

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.e("XY", "onTouchEvent: "+event.getRawX()+"y" +event.getRawY());
        return super.onTouchEvent(event);
    }
}
